home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / djgpp / docs / make / make.i2 < prev    next >
Encoding:
GNU Info File  |  1994-07-27  |  49.9 KB  |  1,253 lines

  1. This is Info file make.info, produced by Makeinfo-1.54 from the input
  2. file ./make.texinfo.
  3.  
  4.    This file documents the GNU Make utility, which determines
  5. automatically which pieces of a large program need to be recompiled,
  6. and issues the commands to recompile them.
  7.  
  8.    This is Edition 0.45, last updated 11 May 1994, of `The GNU Make
  9. Manual', for `make', Version 3.71 Beta.
  10.  
  11.    Copyright (C) 1988, '89, '90, '91, '92, '93, '94 Free Software
  12. Foundation, Inc.
  13.  
  14.    Permission is granted to make and distribute verbatim copies of this
  15. manual provided the copyright notice and this permission notice are
  16. preserved on all copies.
  17.  
  18.    Permission is granted to copy and distribute modified versions of
  19. this manual under the conditions for verbatim copying, provided that
  20. the entire resulting derived work is distributed under the terms of a
  21. permission notice identical to this one.
  22.  
  23.    Permission is granted to copy and distribute translations of this
  24. manual into another language, under the above conditions for modified
  25. versions, except that this permission notice may be stated in a
  26. translation approved by the Free Software Foundation.
  27.  
  28. 
  29. File: make.info,  Node: Rule Example,  Next: Rule Syntax,  Up: Rules
  30.  
  31. Rule Example
  32. ============
  33.  
  34.    Here is an example of a rule:
  35.  
  36.      foo.o : foo.c defs.h       # module for twiddling the frobs
  37.              cc -c -g foo.c
  38.  
  39.    Its target is `foo.o' and its dependencies are `foo.c' and `defs.h'.
  40. It has one command, which is `cc -c -g foo.c'.  The command line
  41. starts with a tab to identify it as a command.
  42.  
  43.    This rule says two things:
  44.  
  45.    * How to decide whether `foo.o' is out of date: it is out of date if
  46.      it does not exist, or if either `foo.c' or `defs.h' is more recent
  47.      than it.
  48.  
  49.    * How to update the file `foo.o': by running `cc' as stated.  The
  50.      command does not explicitly mention `defs.h', but we presume that
  51.      `foo.c' includes it, and that that is why `defs.h' was added to
  52.      the dependencies.
  53.  
  54. 
  55. File: make.info,  Node: Rule Syntax,  Next: Wildcards,  Prev: Rule Example,  Up: Rules
  56.  
  57. Rule Syntax
  58. ===========
  59.  
  60.    In general, a rule looks like this:
  61.  
  62.      TARGETS : DEPENDENCIES
  63.              COMMAND
  64.              ...
  65.  
  66. or like this:
  67.  
  68.      TARGETS : DEPENDENCIES ; COMMAND
  69.              COMMAND
  70.              ...
  71.  
  72.    The TARGETS are file names, separated by spaces.  Wildcard
  73. characters may be used (*note Using Wildcard Characters in File Names:
  74. Wildcards.) and a name of the form `A(M)' represents member M in
  75. archive file A (*note Archive Members as Targets: Archive Members.).
  76. Usually there is only one target per rule, but occasionally there is a
  77. reason to have more (*note Multiple Targets in a Rule: Multiple
  78. Targets.).
  79.  
  80.    The COMMAND lines start with a tab character.  The first command may
  81. appear on the line after the dependencies, with a tab character, or may
  82. appear on the same line, with a semicolon.  Either way, the effect is
  83. the same.  *Note Writing the Commands in Rules: Commands.
  84.  
  85.    Because dollar signs are used to start variable references, if you
  86. really want a dollar sign in a rule you must write two of them, `$$'
  87. (*note How to Use Variables: Using Variables.).  You may split a long
  88. line by inserting a backslash followed by a newline, but this is not
  89. required, as `make' places no limit on the length of a line in a
  90. makefile.
  91.  
  92.    A rule tells `make' two things: when the targets are out of date,
  93. and how to update them when necessary.
  94.  
  95.    The criterion for being out of date is specified in terms of the
  96. DEPENDENCIES, which consist of file names separated by spaces.
  97. (Wildcards and archive members (*note Archives::.) are allowed here
  98. too.) A target is out of date if it does not exist or if it is older
  99. than any of the dependencies (by comparison of last-modification
  100. times).  The idea is that the contents of the target file are computed
  101. based on information in the dependencies, so if any of the dependencies
  102. changes, the contents of the existing target file are no longer
  103. necessarily valid.
  104.  
  105.    How to update is specified by COMMANDS.  These are lines to be
  106. executed by the shell (normally `sh'), but with some extra features
  107. (*note Writing the Commands in Rules: Commands.).
  108.  
  109. 
  110. File: make.info,  Node: Wildcards,  Next: Directory Search,  Prev: Rule Syntax,  Up: Rules
  111.  
  112. Using Wildcard Characters in File Names
  113. =======================================
  114.  
  115.    A single file name can specify many files using "wildcard
  116. characters".  The wildcard characters in `make' are `*', `?' and
  117. `[...]', the same as in the Bourne shell.  For example, `*.c' specifies
  118. a list of all the files (in the working directory) whose names end in
  119. `.c'.
  120.  
  121.    The character `~' at the beginning of a file name also has special
  122. significance.  If alone, or followed by a slash, it represents your home
  123. directory.  For example `~/bin' expands to `/home/you/bin'.  If the `~'
  124. is followed by a word, the string represents the home directory of the
  125. user named by that word.  For example `~john/bin' expands to
  126. `/home/john/bin'.
  127.  
  128.    Wildcard expansion happens automatically in targets, in dependencies,
  129. and in commands (where the shell does the expansion).  In other
  130. contexts, wildcard expansion happens only if you request it explicitly
  131. with the `wildcard' function.
  132.  
  133.    The special significance of a wildcard character can be turned off by
  134. preceding it with a backslash.  Thus, `foo\*bar' would refer to a
  135. specific file whose name consists of `foo', an asterisk, and `bar'.
  136.  
  137. * Menu:
  138.  
  139. * Wildcard Examples::           Several examples
  140. * Wildcard Pitfall::            Problems to avoid.
  141. * Wildcard Function::           How to cause wildcard expansion where
  142.                                   it does not normally take place.
  143.  
  144. 
  145. File: make.info,  Node: Wildcard Examples,  Next: Wildcard Pitfall,  Up: Wildcards
  146.  
  147. Wildcard Examples
  148. -----------------
  149.  
  150.    Wildcards can be used in the commands of a rule, where they are
  151. expanded by the shell.  For example, here is a rule to delete all the
  152. object files:
  153.  
  154.      clean:
  155.              rm -f *.o
  156.  
  157.    Wildcards are also useful in the dependencies of a rule.  With the
  158. following rule in the makefile, `make print' will print all the `.c'
  159. files that have changed since the last time you printed them:
  160.  
  161.      print: *.c
  162.              lpr -p $?
  163.              touch print
  164.  
  165. This rule uses `print' as an empty target file; see *Note Empty Target
  166. Files to Record Events: Empty Targets.  (The automatic variable `$?' is
  167. used to print only those files that have changed; see *Note Automatic
  168. Variables: Automatic.)
  169.  
  170.    Wildcard expansion does not happen when you define a variable.
  171. Thus, if you write this:
  172.  
  173.      objects = *.o
  174.  
  175. then the value of the variable `objects' is the actual string `*.o'.
  176. However, if you use the value of `objects' in a target, dependency or
  177. command, wildcard expansion will take place at that time.  To set
  178. `objects' to the expansion, instead use:
  179.  
  180.      objects := $(wildcard *.o)
  181.  
  182. *Note Wildcard Function::.
  183.  
  184. 
  185. File: make.info,  Node: Wildcard Pitfall,  Next: Wildcard Function,  Prev: Wildcard Examples,  Up: Wildcards
  186.  
  187. Pitfalls of Using Wildcards
  188. ---------------------------
  189.  
  190.    Now here is an example of a naive way of using wildcard expansion,
  191. that does not do what you would intend.  Suppose you would like to say
  192. that the executable file `foo' is made from all the object files in the
  193. directory, and you write this:
  194.  
  195.      objects = *.o
  196.      
  197.      foo : $(objects)
  198.              cc -o foo $(CFLAGS) $(objects)
  199.  
  200. The value of `objects' is the actual string `*.o'.  Wildcard expansion
  201. happens in the rule for `foo', so that each *existing* `.o' file
  202. becomes a dependency of `foo' and will be recompiled if necessary.
  203.  
  204.    But what if you delete all the `.o' files?  When a wildcard matches
  205. no files, it is left as it is, so then `foo' will depend on the
  206. oddly-named file `*.o'.  Since no such file is likely to exist, `make'
  207. will give you an error saying it cannot figure out how to make `*.o'.
  208. This is not what you want!
  209.  
  210.    Actually it is possible to obtain the desired result with wildcard
  211. expansion, but you need more sophisticated techniques, including the
  212. `wildcard' function and string substitution.  *Note The Function
  213. `wildcard': Wildcard Function.
  214.  
  215. 
  216. File: make.info,  Node: Wildcard Function,  Prev: Wildcard Pitfall,  Up: Wildcards
  217.  
  218. The Function `wildcard'
  219. -----------------------
  220.  
  221.    Wildcard expansion happens automatically in rules.  But wildcard
  222. expansion does not normally take place when a variable is set, or
  223. inside the arguments of a function.  If you want to do wildcard
  224. expansion in such places, you need to use the `wildcard' function, like
  225. this:
  226.  
  227.      $(wildcard PATTERN...)
  228.  
  229. This string, used anywhere in a makefile, is replaced by a
  230. space-separated list of names of existing files that match one of the
  231. given file name patterns.  If no existing file name matches a pattern,
  232. then that pattern is omitted from the output of the `wildcard'
  233. function.  Note that this is different from how unmatched wildcards
  234. behave in rules, where they are used verbatim rather than ignored
  235. (*note Wildcard Pitfall::.).
  236.  
  237.    One use of the `wildcard' function is to get a list of all the C
  238. source files in a directory, like this:
  239.  
  240.      $(wildcard *.c)
  241.  
  242.    We can change the list of C source files into a list of object files
  243. by replacing the `.o' suffix with `.c' in the result, like this:
  244.  
  245.      $(patsubst %.c,%.o,$(wildcard *.c))
  246.  
  247. (Here we have used another function, `patsubst'.  *Note Functions for
  248. String Substitution and Analysis: Text Functions.)
  249.  
  250.    Thus, a makefile to compile all C source files in the directory and
  251. then link them together could be written as follows:
  252.  
  253.      objects := $(patsubst %.c,%.o,$(wildcard *.c))
  254.      
  255.      foo : $(objects)
  256.              cc -o foo $(objects)
  257.  
  258. (This takes advantage of the implicit rule for compiling C programs, so
  259. there is no need to write explicit rules for compiling the files.
  260. *Note The Two Flavors of Variables: Flavors, for an explanation of
  261. `:=', which is a variant of `='.)
  262.  
  263. 
  264. File: make.info,  Node: Directory Search,  Next: Phony Targets,  Prev: Wildcards,  Up: Rules
  265.  
  266. Searching Directories for Dependencies
  267. ======================================
  268.  
  269.    For large systems, it is often desirable to put sources in a separate
  270. directory from the binaries.  The "directory search" features of `make'
  271. facilitate this by searching several directories automatically to find
  272. a dependency.  When you redistribute the files among directories, you
  273. do not need to change the individual rules, just the search paths.
  274.  
  275. * Menu:
  276.  
  277. * General Search::              Specifying a search path that applies
  278.                                   to every dependency.
  279. * Selective Search::            Specifying a search path
  280.                                   for a specified class of names.
  281. * Commands/Search::             How to write shell commands that work together
  282.                                   with search paths.
  283. * Implicit/Search::             How search paths affect implicit rules.
  284. * Libraries/Search::            Directory search for link libraries.
  285.  
  286. 
  287. File: make.info,  Node: General Search,  Next: Selective Search,  Up: Directory Search
  288.  
  289. `VPATH': Search Path for All Dependencies
  290. -----------------------------------------
  291.  
  292.    The value of the `make' variable `VPATH' specifies a list of
  293. directories that `make' should search.  Most often, the directories are
  294. expected to contain dependency files that are not in the current
  295. directory; however, `VPATH' specifies a search list that `make' applies
  296. for all files, including files which are targets of rules.
  297.  
  298.    Thus, if a file that is listed as a target or dependency does not
  299. exist in the current directory, `make' searches the directories listed
  300. in `VPATH' for a file with that name.  If a file is found in one of
  301. them, that file becomes the dependency.  Rules may then specify the
  302. names of source files in the dependencies as if they all existed in the
  303. current directory.  *Note Writing Shell Commands with Directory Search:
  304. Commands/Search.
  305.  
  306.    In the `VPATH' variable, directory names are separated by colons or
  307. blanks.  The order in which directories are listed is the order followed
  308. by `make' in its search.
  309.  
  310.    For example,
  311.  
  312.      VPATH = src:../headers
  313.  
  314. specifies a path containing two directories, `src' and `../headers',
  315. which `make' searches in that order.
  316.  
  317.    With this value of `VPATH', the following rule,
  318.  
  319.      foo.o : foo.c
  320.  
  321. is interpreted as if it were written like this:
  322.  
  323.      foo.o : src/foo.c
  324.  
  325. assuming the file `foo.c' does not exist in the current directory but
  326. is found in the directory `src'.
  327.  
  328. 
  329. File: make.info,  Node: Selective Search,  Next: Commands/Search,  Prev: General Search,  Up: Directory Search
  330.  
  331. The `vpath' Directive
  332. ---------------------
  333.  
  334.    Similar to the `VPATH' variable but more selective is the `vpath'
  335. directive (note lower case), which allows you to specify a search path
  336. for a particular class of file names, those that match a particular
  337. pattern.  Thus you can supply certain search directories for one class
  338. of file names and other directories (or none) for other file names.
  339.  
  340.    There are three forms of the `vpath' directive:
  341.  
  342. `vpath PATTERN DIRECTORIES'
  343.      Specify the search path DIRECTORIES for file names that match
  344.      PATTERN.
  345.  
  346.      The search path, DIRECTORIES, is a list of directories to be
  347.      searched, separated by colons or blanks, just like the search path
  348.      used in the `VPATH' variable.
  349.  
  350. `vpath PATTERN'
  351.      Clear out the search path associated with PATTERN.
  352.  
  353. `vpath'
  354.      Clear all search paths previously specified with `vpath'
  355.      directives.
  356.  
  357.    A `vpath' pattern is a string containing a `%' character.  The
  358. string must match the file name of a dependency that is being searched
  359. for, the `%' character matching any sequence of zero or more characters
  360. (as in pattern rules; *note Defining and Redefining Pattern Rules:
  361. Pattern Rules.).  For example, `%.h' matches files that end in `.h'.
  362. (If there is no `%', the pattern must match the dependency exactly,
  363. which is not useful very often.)
  364.  
  365.    `%' characters in a `vpath' directive's pattern can be quoted with
  366. preceding backslashes (`\').  Backslashes that would otherwise quote
  367. `%' characters can be quoted with more backslashes.  Backslashes that
  368. quote `%' characters or other backslashes are removed from the pattern
  369. before it is compared to file names.  Backslashes that are not in
  370. danger of quoting `%' characters go unmolested.
  371.  
  372.    When a dependency fails to exist in the current directory, if the
  373. PATTERN in a `vpath' directive matches the name of the dependency file,
  374. then the DIRECTORIES in that directive are searched just like (and
  375. before) the directories in the `VPATH' variable.
  376.  
  377.    For example,
  378.  
  379.      vpath %.h ../headers
  380.  
  381. tells `make' to look for any dependency whose name ends in `.h' in the
  382. directory `../headers' if the file is not found in the current
  383. directory.
  384.  
  385.    If several `vpath' patterns match the dependency file's name, then
  386. `make' processes each matching `vpath' directive one by one, searching
  387. all the directories mentioned in each directive.  `make' handles
  388. multiple `vpath' directives in the order in which they appear in the
  389. makefile; multiple directives with the same pattern are independent of
  390. each other.
  391.  
  392.    Thus,
  393.  
  394.      vpath %.c foo
  395.      vpath %   blish
  396.      vpath %.c bar
  397.  
  398. will look for a file ending in `.c' in `foo', then `blish', then `bar',
  399. while
  400.  
  401.      vpath %.c foo:bar
  402.      vpath %   blish
  403.  
  404. will look for a file ending in `.c' in `foo', then `bar', then `blish'.
  405.  
  406. 
  407. File: make.info,  Node: Commands/Search,  Next: Implicit/Search,  Prev: Selective Search,  Up: Directory Search
  408.  
  409. Writing Shell Commands with Directory Search
  410. --------------------------------------------
  411.  
  412.    When a dependency is found in another directory through directory
  413. search, this cannot change the commands of the rule; they will execute
  414. as written.  Therefore, you must write the commands with care so that
  415. they will look for the dependency in the directory where `make' finds
  416. it.
  417.  
  418.    This is done with the "automatic variables" such as `$^' (*note
  419. Automatic Variables: Automatic.).  For instance, the value of `$^' is a
  420. list of all the dependencies of the rule, including the names of the
  421. directories in which they were found, and the value of `$@' is the
  422. target.  Thus:
  423.  
  424.      foo.o : foo.c
  425.              cc -c $(CFLAGS) $^ -o $@
  426.  
  427. (The variable `CFLAGS' exists so you can specify flags for C
  428. compilation by implicit rules; we use it here for consistency so it will
  429. affect all C compilations uniformly; *note Variables Used by Implicit
  430. Rules: Implicit Variables..)
  431.  
  432.    Often the dependencies include header files as well, which you do not
  433. want to mention in the commands.  The automatic variable `$<' is just
  434. the first dependency:
  435.  
  436.      VPATH = src:../headers
  437.      foo.o : foo.c defs.h hack.h
  438.              cc -c $(CFLAGS) $< -o $@
  439.  
  440. 
  441. File: make.info,  Node: Implicit/Search,  Next: Libraries/Search,  Prev: Commands/Search,  Up: Directory Search
  442.  
  443. Directory Search and Implicit Rules
  444. -----------------------------------
  445.  
  446.    The search through the directories specified in `VPATH' or with
  447. `vpath' also happens during consideration of implicit rules (*note
  448. Using Implicit Rules: Implicit Rules.).
  449.  
  450.    For example, when a file `foo.o' has no explicit rule, `make'
  451. considers implicit rules, such as the built-in rule to compile `foo.c'
  452. if that file exists.  If such a file is lacking in the current
  453. directory, the appropriate directories are searched for it.  If `foo.c'
  454. exists (or is mentioned in the makefile) in any of the directories, the
  455. implicit rule for C compilation is applied.
  456.  
  457.    The commands of implicit rules normally use automatic variables as a
  458. matter of necessity; consequently they will use the file names found by
  459. directory search with no extra effort.
  460.  
  461. 
  462. File: make.info,  Node: Libraries/Search,  Prev: Implicit/Search,  Up: Directory Search
  463.  
  464. Directory Search for Link Libraries
  465. -----------------------------------
  466.  
  467.    Directory search applies in a special way to libraries used with the
  468. linker.  This special feature comes into play when you write a
  469. dependency whose name is of the form `-lNAME'.  (You can tell something
  470. strange is going on here because the dependency is normally the name of
  471. a file, and the *file name* of the library looks like `libNAME.a', not
  472. like `-lNAME'.)
  473.  
  474.    When a dependency's name has the form `-lNAME', `make' handles it
  475. specially by searching for the file `libNAME.a' in the current
  476. directory, in directories specified by matching `vpath' search paths
  477. and the `VPATH' search path, and then in the directories `/lib',
  478. `/usr/lib', and `PREFIX/lib' (normally `/usr/local/lib').
  479.  
  480.    For example,
  481.  
  482.      foo : foo.c -lcurses
  483.              cc $^ -o $@
  484.  
  485. would cause the command `cc foo.c /usr/lib/libcurses.a -o foo' to be
  486. executed when `foo' is older than `foo.c' or than
  487. `/usr/lib/libcurses.a'.
  488.  
  489. 
  490. File: make.info,  Node: Phony Targets,  Next: Force Targets,  Prev: Directory Search,  Up: Rules
  491.  
  492. Phony Targets
  493. =============
  494.  
  495.    A phony target is one that is not really the name of a file.  It is
  496. just a name for some commands to be executed when you make an explicit
  497. request.  There are two reasons to use a phony target: to avoid a
  498. conflict with a file of the same name, and to improve performance.
  499.  
  500.    If you write a rule whose commands will not create the target file,
  501. the commands will be executed every time the target comes up for
  502. remaking.  Here is an example:
  503.  
  504.      clean:
  505.              rm *.o temp
  506.  
  507. Because the `rm' command does not create a file named `clean', probably
  508. no such file will ever exist.  Therefore, the `rm' command will be
  509. executed every time you say `make clean'.
  510.  
  511.    The phony target will cease to work if anything ever does create a
  512. file named `clean' in this directory.  Since it has no dependencies, the
  513. file `clean' would inevitably be considered up to date, and its
  514. commands would not be executed.  To avoid this problem, you can
  515. explicitly declare the target to be phony, using the special target
  516. `.PHONY' (*note Special Built-in Target Names: Special Targets.) as
  517. follows:
  518.  
  519.      .PHONY : clean
  520.  
  521. Once this is done, `make clean' will run the commands regardless of
  522. whether there is a file named `clean'.
  523.  
  524.    Since it knows that phony targets do not name actual files that
  525. could be remade from other files, `make' skips the implicit rule search
  526. for phony targets (*note Implicit Rules::.).  This is why declaring a
  527. target phony is good for performance, even if you are not worried about
  528. the actual file existing.
  529.  
  530.    Thus, you first write the line that states that `clean' is a phony
  531. target, then you write the rule, like this:
  532.  
  533.      .PHONY: clean
  534.      clean:
  535.              rm *.o temp
  536.  
  537.    A phony target should not be a dependency of a real target file; if
  538. it is, its commands are run every time `make' goes to update that file.
  539. As long as a phony target is never a dependency of a real target, the
  540. phony target commands will be executed only when the phony target is a
  541. specified goal (*note Arguments to Specify the Goals: Goals.).
  542.  
  543.    Phony targets can have dependencies.  When one directory contains
  544. multiple programs, it is most convenient to describe all of the
  545. programs in one makefile `./Makefile'.  Since the target remade by
  546. default will be the first one in the makefile, it is common to make
  547. this a phony target named `all' and give it, as dependencies, all the
  548. individual programs.  For example:
  549.  
  550.      all : prog1 prog2 prog3
  551.      .PHONY : all
  552.      
  553.      prog1 : prog1.o utils.o
  554.              cc -o prog1 prog1.o utils.o
  555.      
  556.      prog2 : prog2.o
  557.              cc -o prog2 prog2.o
  558.      
  559.      prog3 : prog3.o sort.o utils.o
  560.              cc -o prog3 prog3.o sort.o utils.o
  561.  
  562. Now you can say just `make' to remake all three programs, or specify as
  563. arguments the ones to remake (as in `make prog1 prog3').
  564.  
  565.    When one phony target is a dependency of another, it serves as a
  566. subroutine of the other.  For example, here `make cleanall' will delete
  567. the object files, the difference files, and the file `program':
  568.  
  569.      .PHONY: cleanall cleanobj cleandiff
  570.      
  571.      cleanall : cleanobj cleandiff
  572.              rm program
  573.      
  574.      cleanobj :
  575.              rm *.o
  576.      
  577.      cleandiff :
  578.              rm *.diff
  579.  
  580. 
  581. File: make.info,  Node: Force Targets,  Next: Empty Targets,  Prev: Phony Targets,  Up: Rules
  582.  
  583. Rules without Commands or Dependencies
  584. ======================================
  585.  
  586.    If a rule has no dependencies or commands, and the target of the rule
  587. is a nonexistent file, then `make' imagines this target to have been
  588. updated whenever its rule is run.  This implies that all targets
  589. depending on this one will always have their commands run.
  590.  
  591.    An example will illustrate this:
  592.  
  593.      clean: FORCE
  594.              rm $(objects)
  595.      FORCE:
  596.  
  597.    Here the target `FORCE' satisfies the special conditions, so the
  598. target `clean' that depends on it is forced to run its commands.  There
  599. is nothing special about the name `FORCE', but that is one name
  600. commonly used this way.
  601.  
  602.    As you can see, using `FORCE' this way has the same results as using
  603. `.PHONY: clean'.
  604.  
  605.    Using `.PHONY' is more explicit and more efficient.  However, other
  606. versions of `make' do not support `.PHONY'; thus `FORCE' appears in
  607. many makefiles.  *Note Phony Targets::.
  608.  
  609. 
  610. File: make.info,  Node: Empty Targets,  Next: Special Targets,  Prev: Force Targets,  Up: Rules
  611.  
  612. Empty Target Files to Record Events
  613. ===================================
  614.  
  615.    The "empty target" is a variant of the phony target; it is used to
  616. hold commands for an action that you request explicitly from time to
  617. time.  Unlike a phony target, this target file can really exist; but
  618. the file's contents do not matter, and usually are empty.
  619.  
  620.    The purpose of the empty target file is to record, with its
  621. last-modification time, when the rule's commands were last executed.  It
  622. does so because one of the commands is a `touch' command to update the
  623. target file.
  624.  
  625.    The empty target file must have some dependencies.  When you ask to
  626. remake the empty target, the commands are executed if any dependency is
  627. more recent than the target; in other words, if a dependency has
  628. changed since the last time you remade the target.  Here is an example:
  629.  
  630.      print: foo.c bar.c
  631.              lpr -p $?
  632.              touch print
  633.  
  634. With this rule, `make print' will execute the `lpr' command if either
  635. source file has changed since the last `make print'.  The automatic
  636. variable `$?' is used to print only those files that have changed
  637. (*note Automatic Variables: Automatic.).
  638.  
  639. 
  640. File: make.info,  Node: Special Targets,  Next: Multiple Targets,  Prev: Empty Targets,  Up: Rules
  641.  
  642. Special Built-in Target Names
  643. =============================
  644.  
  645.    Certain names have special meanings if they appear as targets.
  646.  
  647. `.PHONY'
  648.      The dependencies of the special target `.PHONY' are considered to
  649.      be phony targets.  When it is time to consider such a target,
  650.      `make' will run its commands unconditionally, regardless of
  651.      whether a file with that name exists or what its last-modification
  652.      time is.  *Note Phony Targets: Phony Targets.
  653.  
  654. `.SUFFIXES'
  655.      The dependencies of the special target `.SUFFIXES' are the list of
  656.      suffixes to be used in checking for suffix rules.  *Note
  657.      Old-Fashioned Suffix Rules: Suffix Rules.
  658.  
  659. `.DEFAULT'
  660.      The commands specified for `.DEFAULT' are used for any target for
  661.      which no rules are found (either explicit rules or implicit rules).
  662.      *Note Last Resort::.  If `.DEFAULT' commands are specified, every
  663.      file mentioned as a dependency, but not as a target in a rule,
  664.      will have these commands executed on its behalf.  *Note Implicit
  665.      Rule Search Algorithm: Search Algorithm.
  666.  
  667. `.PRECIOUS'
  668.      The targets which `.PRECIOUS' depends on are given the following
  669.      special treatment: if `make' is killed or interrupted during the
  670.      execution of their commands, the target is not deleted.  *Note
  671.      Interrupting or Killing `make': Interrupts.  Also, if the target
  672.      is an intermediate file, it will not be deleted after it is no
  673.      longer needed, as is normally done.  *Note Chains of Implicit
  674.      Rules: Chained Rules.
  675.  
  676.      You can also list the target pattern of an implicit rule (such as
  677.      `%.o') as a dependency file of the special target `.PRECIOUS' to
  678.      preserve intermediate files created by rules whose target patterns
  679.      match that file's name.
  680.  
  681. `.IGNORE'
  682.      Simply by being mentioned as a target, `.IGNORE' says to ignore
  683.      errors in execution of commands.  The dependencies and commands for
  684.      `.IGNORE' are not meaningful.
  685.  
  686.      `.IGNORE' exists for historical compatibility.  Since `.IGNORE'
  687.      affects every command in the makefile, it is not very useful; we
  688.      recommend you use the more selective ways to ignore errors in
  689.      specific commands.  *Note Errors in Commands: Errors.
  690.  
  691. `.SILENT'
  692.      Simply by being mentioned as a target, `.SILENT' says not to print
  693.      commands before executing them.  The dependencies and commands for
  694.      `.SILENT' are not meaningful.
  695.  
  696.      `.SILENT' exists for historical compatibility.  We recommend you
  697.      use the more selective ways to silence specific commands.  *Note
  698.      Command Echoing: Echoing.  If you want to silence all commands for
  699.      a particular run of `make', use the `-s' or `--silent' option
  700.      (*note Options Summary::.).
  701.  
  702. `.EXPORT_ALL_VARIABLES'
  703.      Simply by being mentioned as a target, this tells `make' to export
  704.      all variables to child processes by default.  *Note Communicating
  705.      Variables to a Sub-`make': Variables/Recursion.
  706.  
  707.    Any defined implicit rule suffix also counts as a special target if
  708. it appears as a target, and so does the concatenation of two suffixes,
  709. such as `.c.o'.  These targets are suffix rules, an obsolete way of
  710. defining implicit rules (but a way still widely used).  In principle,
  711. any target name could be special in this way if you break it in two and
  712. add both pieces to the suffix list.  In practice, suffixes normally
  713. begin with `.', so these special target names also begin with `.'.
  714. *Note Old-Fashioned Suffix Rules: Suffix Rules.
  715.  
  716. 
  717. File: make.info,  Node: Multiple Targets,  Next: Multiple Rules,  Prev: Special Targets,  Up: Rules
  718.  
  719. Multiple Targets in a Rule
  720. ==========================
  721.  
  722.    A rule with multiple targets is equivalent to writing many rules,
  723. each with one target, and all identical aside from that.  The same
  724. commands apply to all the targets, but their effects may vary because
  725. you can substitute the actual target name into the command using `$@'.
  726. The rule contributes the same dependencies to all the targets also.
  727.  
  728.    This is useful in two cases.
  729.  
  730.    * You want just dependencies, no commands.  For example:
  731.  
  732.           kbd.o command.o files.o: command.h
  733.  
  734.      gives an additional dependency to each of the three object files
  735.      mentioned.
  736.  
  737.    * Similar commands work for all the targets.  The commands do not
  738.      need to be absolutely identical, since the automatic variable `$@'
  739.      can be used to substitute the particular target to be remade into
  740.      the commands (*note Automatic Variables: Automatic.).  For example:
  741.  
  742.           bigoutput littleoutput : text.g
  743.                   generate text.g -$(subst output,,$@) > $@
  744.  
  745.      is equivalent to
  746.  
  747.           bigoutput : text.g
  748.                   generate text.g -big > bigoutput
  749.           littleoutput : text.g
  750.                   generate text.g -little > littleoutput
  751.  
  752.      Here we assume the hypothetical program `generate' makes two types
  753.      of output, one if given `-big' and one if given `-little'.  *Note
  754.      Functions for String Substitution and Analysis: Text Functions,
  755.      for an explanation of the `subst' function.
  756.  
  757.    Suppose you would like to vary the dependencies according to the
  758. target, much as the variable `$@' allows you to vary the commands.  You
  759. cannot do this with multiple targets in an ordinary rule, but you can
  760. do it with a "static pattern rule".  *Note Static Pattern Rules: Static
  761. Pattern.
  762.  
  763. 
  764. File: make.info,  Node: Multiple Rules,  Next: Static Pattern,  Prev: Multiple Targets,  Up: Rules
  765.  
  766. Multiple Rules for One Target
  767. =============================
  768.  
  769.    One file can be the target of several rules.  All the dependencies
  770. mentioned in all the rules are merged into one list of dependencies for
  771. the target.  If the target is older than any dependency from any rule,
  772. the commands are executed.
  773.  
  774.    There can only be one set of commands to be executed for a file.  If
  775. more than one rule gives commands for the same file, `make' uses the
  776. last set given and prints an error message.  (As a special case, if the
  777. file's name begins with a dot, no error message is printed.  This odd
  778. behavior is only for compatibility with other implementations of
  779. `make'.) There is no reason to write your makefiles this way; that is
  780. why `make' gives you an error message.
  781.  
  782.    An extra rule with just dependencies can be used to give a few extra
  783. dependencies to many files at once.  For example, one usually has a
  784. variable named `objects' containing a list of all the compiler output
  785. files in the system being made.  An easy way to say that all of them
  786. must be recompiled if `config.h' changes is to write the following:
  787.  
  788.      objects = foo.o bar.o
  789.      foo.o : defs.h
  790.      bar.o : defs.h test.h
  791.      $(objects) : config.h
  792.  
  793.    This could be inserted or taken out without changing the rules that
  794. really specify how to make the object files, making it a convenient
  795. form to use if you wish to add the additional dependency intermittently.
  796.  
  797.    Another wrinkle is that the additional dependencies could be
  798. specified with a variable that you set with a command argument to `make'
  799. (*note Overriding Variables: Overriding.).  For example,
  800.  
  801.      extradeps=
  802.      $(objects) : $(extradeps)
  803.  
  804. means that the command `make extradeps=foo.h' will consider `foo.h' as
  805. a dependency of each object file, but plain `make' will not.
  806.  
  807.    If none of the explicit rules for a target has commands, then `make'
  808. searches for an applicable implicit rule to find some commands *note
  809. Using Implicit Rules: Implicit Rules.).
  810.  
  811. 
  812. File: make.info,  Node: Static Pattern,  Next: Double-Colon,  Prev: Multiple Rules,  Up: Rules
  813.  
  814. Static Pattern Rules
  815. ====================
  816.  
  817.    "Static pattern rules" are rules which specify multiple targets and
  818. construct the dependency names for each target based on the target name.
  819. They are more general than ordinary rules with multiple targets because
  820. the targets do not have to have identical dependencies.  Their
  821. dependencies must be *analogous*, but not necessarily *identical*.
  822.  
  823. * Menu:
  824.  
  825. * Static Usage::                The syntax of static pattern rules.
  826. * Static versus Implicit::      When are they better than implicit rules?
  827.  
  828. 
  829. File: make.info,  Node: Static Usage,  Next: Static versus Implicit,  Up: Static Pattern
  830.  
  831. Syntax of Static Pattern Rules
  832. ------------------------------
  833.  
  834.    Here is the syntax of a static pattern rule:
  835.  
  836.      TARGETS ...: TARGET-PATTERN: DEP-PATTERNS ...
  837.              COMMANDS
  838.              ...
  839.  
  840. The TARGETS list specifies the targets that the rule applies to.  The
  841. targets can contain wildcard characters, just like the targets of
  842. ordinary rules (*note Using Wildcard Characters in File Names:
  843. Wildcards.).
  844.  
  845.    The TARGET-PATTERN and DEP-PATTERNS say how to compute the
  846. dependencies of each target.  Each target is matched against the
  847. TARGET-PATTERN to extract a part of the target name, called the "stem".
  848. This stem is substituted into each of the DEP-PATTERNS to make the
  849. dependency names (one from each DEP-PATTERN).
  850.  
  851.    Each pattern normally contains the character `%' just once.  When the
  852. TARGET-PATTERN matches a target, the `%' can match any part of the
  853. target name; this part is called the "stem".  The rest of the pattern
  854. must match exactly.  For example, the target `foo.o' matches the
  855. pattern `%.o', with `foo' as the stem.  The targets `foo.c' and
  856. `foo.out' do not match that pattern.
  857.  
  858.    The dependency names for each target are made by substituting the
  859. stem for the `%' in each dependency pattern.  For example, if one
  860. dependency pattern is `%.c', then substitution of the stem `foo' gives
  861. the dependency name `foo.c'.  It is legitimate to write a dependency
  862. pattern that does not contain `%'; then this dependency is the same for
  863. all targets.
  864.  
  865.    `%' characters in pattern rules can be quoted with preceding
  866. backslashes (`\').  Backslashes that would otherwise quote `%'
  867. characters can be quoted with more backslashes.  Backslashes that quote
  868. `%' characters or other backslashes are removed from the pattern before
  869. it is compared to file names or has a stem substituted into it.
  870. Backslashes that are not in danger of quoting `%' characters go
  871. unmolested.  For example, the pattern `the\%weird\\%pattern\\' has
  872. `the%weird\' preceding the operative `%' character, and `pattern\\'
  873. following it.  The final two backslashes are left alone because they
  874. cannot affect any `%' character.
  875.  
  876.    Here is an example, which compiles each of `foo.o' and `bar.o' from
  877. the corresponding `.c' file:
  878.  
  879.      objects = foo.o bar.o
  880.      
  881.      $(objects): %.o: %.c
  882.              $(CC) -c $(CFLAGS) $< -o $@
  883.  
  884. Here `$<' is the automatic variable that holds the name of the
  885. dependency and `$@' is the automatic variable that holds the name of
  886. the target; see *Note Automatic Variables: Automatic.
  887.  
  888.    Each target specified must match the target pattern; a warning is
  889. issued for each target that does not.  If you have a list of files,
  890. only some of which will match the pattern, you can use the `filter'
  891. function to remove nonmatching file names (*note Functions for String
  892. Substitution and Analysis: Text Functions.):
  893.  
  894.      files = foo.elc bar.o lose.o
  895.      
  896.      $(filter %.o,$(files)): %.o: %.c
  897.              $(CC) -c $(CFLAGS) $< -o $@
  898.      $(filter %.elc,$(files)): %.elc: %.el
  899.              emacs -f batch-byte-compile $<
  900.  
  901. In this example the result of `$(filter %.o,$(files))' is `bar.o
  902. lose.o', and the first static pattern rule causes each of these object
  903. files to be updated by compiling the corresponding C source file.  The
  904. result of `$(filter %.elc,$(files))' is `foo.elc', so that file is made
  905. from `foo.el'.
  906.  
  907.    Another example shows how to use `$*' in static pattern rules:
  908.  
  909.      bigoutput littleoutput : %output : text.g
  910.              generate text.g -$* > $@
  911.  
  912. When the `generate' command is run, `$*' will expand to the stem,
  913. either `big' or `little'.
  914.  
  915. 
  916. File: make.info,  Node: Static versus Implicit,  Prev: Static Usage,  Up: Static Pattern
  917.  
  918. Static Pattern Rules versus Implicit Rules
  919. ------------------------------------------
  920.  
  921.    A static pattern rule has much in common with an implicit rule
  922. defined as a pattern rule (*note Defining and Redefining Pattern Rules:
  923. Pattern Rules.).  Both have a pattern for the target and patterns for
  924. constructing the names of dependencies.  The difference is in how
  925. `make' decides *when* the rule applies.
  926.  
  927.    An implicit rule *can* apply to any target that matches its pattern,
  928. but it *does* apply only when the target has no commands otherwise
  929. specified, and only when the dependencies can be found.  If more than
  930. one implicit rule appears applicable, only one applies; the choice
  931. depends on the order of rules.
  932.  
  933.    By contrast, a static pattern rule applies to the precise list of
  934. targets that you specify in the rule.  It cannot apply to any other
  935. target and it invariably does apply to each of the targets specified.
  936. If two conflicting rules apply, and both have commands, that's an error.
  937.  
  938.    The static pattern rule can be better than an implicit rule for these
  939. reasons:
  940.  
  941.    * You may wish to override the usual implicit rule for a few files
  942.      whose names cannot be categorized syntactically but can be given
  943.      in an explicit list.
  944.  
  945.    * If you cannot be sure of the precise contents of the directories
  946.      you are using, you may not be sure which other irrelevant files
  947.      might lead `make' to use the wrong implicit rule.  The choice
  948.      might depend on the order in which the implicit rule search is
  949.      done.  With static pattern rules, there is no uncertainty: each
  950.      rule applies to precisely the targets specified.
  951.  
  952. 
  953. File: make.info,  Node: Double-Colon,  Next: Automatic Dependencies,  Prev: Static Pattern,  Up: Rules
  954.  
  955. Double-Colon Rules
  956. ==================
  957.  
  958.    "Double-colon" rules are rules written with `::' instead of `:'
  959. after the target names.  They are handled differently from ordinary
  960. rules when the same target appears in more than one rule.
  961.  
  962.    When a target appears in multiple rules, all the rules must be the
  963. same type: all ordinary, or all double-colon.  If they are
  964. double-colon, each of them is independent of the others.  Each
  965. double-colon rule's commands are executed if the target is older than
  966. any dependencies of that rule.  This can result in executing none, any,
  967. or all of the double-colon rules.
  968.  
  969.    Double-colon rules with the same target are in fact completely
  970. separate from one another.  Each double-colon rule is processed
  971. individually, just as rules with different targets are processed.
  972.  
  973.    The double-colon rules for a target are executed in the order they
  974. appear in the makefile.  However, the cases where double-colon rules
  975. really make sense are those where the order of executing the commands
  976. would not matter.
  977.  
  978.    Double-colon rules are somewhat obscure and not often very useful;
  979. they provide a mechanism for cases in which the method used to update a
  980. target differs depending on which dependency files caused the update,
  981. and such cases are rare.
  982.  
  983.    Each double-colon rule should specify commands; if it does not, an
  984. implicit rule will be used if one applies.  *Note Using Implicit Rules:
  985. Implicit Rules.
  986.  
  987. 
  988. File: make.info,  Node: Automatic Dependencies,  Prev: Double-Colon,  Up: Rules
  989.  
  990. Generating Dependencies Automatically
  991. =====================================
  992.  
  993.    In the makefile for a program, many of the rules you need to write
  994. often say only that some object file depends on some header file.  For
  995. example, if `main.c' uses `defs.h' via an `#include', you would write:
  996.  
  997.      main.o: defs.h
  998.  
  999. You need this rule so that `make' knows that it must remake `main.o'
  1000. whenever `defs.h' changes.  You can see that for a large program you
  1001. would have to write dozens of such rules in your makefile.  And, you
  1002. must always be very careful to update the makefile every time you add
  1003. or remove an `#include'.
  1004.  
  1005.    To avoid this hassle, most modern C compilers can write these rules
  1006. for you, by looking at the `#include' lines in the source files.
  1007. Usually this is done with the `-M' option to the compiler.  For
  1008. example, the command:
  1009.  
  1010.      cc -M main.c
  1011.  
  1012. generates the output:
  1013.  
  1014.      main.o : main.c defs.h
  1015.  
  1016. Thus you no longer have to write all those rules yourself.  The
  1017. compiler will do it for you.
  1018.  
  1019.    Note that such a dependency constitutes mentioning `main.o' in a
  1020. makefile, so it can never be considered an intermediate file by implicit
  1021. rule search.  This means that `make' won't ever remove the file after
  1022. using it; *note Chains of Implicit Rules: Chained Rules..
  1023.  
  1024.    With old `make' programs, it was traditional practice to use this
  1025. compiler feature to generate dependencies on demand with a command like
  1026. `make depend'.  That command would create a file `depend' containing
  1027. all the automatically-generated dependencies; then the makefile could
  1028. use `include' to read them in (*note Include::.).
  1029.  
  1030.    In GNU `make', the feature of remaking makefiles makes this practice
  1031. obsolete--you need never tell `make' explicitly to regenerate the
  1032. dependencies, because it always regenerates any makefile that is out of
  1033. date.  *Note Remaking Makefiles::.
  1034.  
  1035.    The practice we recommend for automatic dependency generation is to
  1036. have one makefile corresponding to each source file.  For each source
  1037. file `NAME.c' there is a makefile `NAME.d' which lists what files the
  1038. object file `NAME.o' depends on.  That way only the source files that
  1039. have changed need to be rescanned to produce the new dependencies.
  1040.  
  1041.    Here is the pattern rule to generate a file of dependencies (i.e., a
  1042. makefile) called `NAME.d' from a C source file called `NAME.c':
  1043.  
  1044.      %.d: %.c
  1045.              $(SHELL) -ec '$(CC) -M $(CPPFLAGS) $< | sed '\''s/$*.o/& $@/g'\'' > $@'
  1046.  
  1047. *Note Pattern Rules::, for information on defining pattern rules.  The
  1048. `-e' flag to the shell makes it exit immediately if the `$(CC)' command
  1049. fails (exits with a nonzero status).  Normally the shell exits with the
  1050. status of the last command in the pipeline (`sed' in this case), so
  1051. `make' would not notice a nonzero status from the compiler.
  1052.  
  1053.    The purpose of the `sed' command is to translate (for example):
  1054.  
  1055.      main.o : main.c defs.h
  1056.  
  1057. into:
  1058.  
  1059.      main.o main.d : main.c defs.h
  1060.  
  1061. This makes each `.d' file depend on all the source and header files
  1062. that the corresponding `.o' file depends on.  `make' then knows it must
  1063. regenerate the dependencies whenever any of the source or header files
  1064. changes.
  1065.  
  1066.    Once you've defined the rule to remake the `.d' files, you then use
  1067. the `include' directive to read them all in.  *Note Include::.  For
  1068. example:
  1069.  
  1070.      sources = foo.c bar.c
  1071.      
  1072.      include $(sources:.c=.d)
  1073.  
  1074. (This example uses a substitution variable reference to translate the
  1075. list of source files `foo.c bar.c' into a list of dependency makefiles,
  1076. `foo.d bar.d'.  *Note Substitution Refs::, for full information on
  1077. substitution references.)  Since the `.d' files are makefiles like any
  1078. others, `make' will remake them as necessary with no further work from
  1079. you.  *Note Remaking Makefiles::.
  1080.  
  1081. 
  1082. File: make.info,  Node: Commands,  Next: Using Variables,  Prev: Rules,  Up: Top
  1083.  
  1084. Writing the Commands in Rules
  1085. *****************************
  1086.  
  1087.    The commands of a rule consist of shell command lines to be executed
  1088. one by one.  Each command line must start with a tab, except that the
  1089. first command line may be attached to the target-and-dependencies line
  1090. with a semicolon in between.  Blank lines and lines of just comments
  1091. may appear among the command lines; they are ignored.
  1092.  
  1093.    Users use many different shell programs, but commands in makefiles
  1094. are always interpreted by `/bin/sh' unless the makefile specifies
  1095. otherwise.  *Note Command Execution: Execution.
  1096.  
  1097.    The shell that is in use determines whether comments can be written
  1098. on command lines, and what syntax they use.  When the shell is
  1099. `/bin/sh', a `#' starts a comment that extends to the end of the line.
  1100. The `#' does not have to be at the beginning of a line.  Text on a line
  1101. before a `#' is not part of the comment.
  1102.  
  1103. * Menu:
  1104.  
  1105. * Echoing::                     How to control when commands are echoed.
  1106. * Execution::                   How commands are executed.
  1107. * Parallel::                    How commands can be executed in parallel.
  1108. * Errors::                      What happens after a command execution error.
  1109. * Interrupts::                  What happens when a command is interrupted.
  1110. * Recursion::                   Invoking `make' from makefiles.
  1111. * Sequences::                   Defining canned sequences of commands.
  1112. * Empty Commands::              Defining useful, do-nothing commands.
  1113.  
  1114. 
  1115. File: make.info,  Node: Echoing,  Next: Execution,  Up: Commands
  1116.  
  1117. Command Echoing
  1118. ===============
  1119.  
  1120.    Normally `make' prints each command line before it is executed.  We
  1121. call this "echoing" because it gives the appearance that you are typing
  1122. the commands yourself.
  1123.  
  1124.    When a line starts with `@', the echoing of that line is suppressed.
  1125. The `@' is discarded before the command is passed to the shell.
  1126. Typically you would use this for a command whose only effect is to print
  1127. something, such as an `echo' command to indicate progress through the
  1128. makefile:
  1129.  
  1130.      @echo About to make distribution files
  1131.  
  1132.    When `make' is given the flag `-n' or `--just-print', echoing is all
  1133. that happens, no execution.  *Note Summary of Options: Options Summary.
  1134. In this case and only this case, even the commands starting with `@'
  1135. are printed.  This flag is useful for finding out which commands `make'
  1136. thinks are necessary without actually doing them.
  1137.  
  1138.    The `-s' or `--silent' flag to `make' prevents all echoing, as if
  1139. all commands started with `@'.  A rule in the makefile for the special
  1140. target `.SILENT' has the same effect (*note Special Built-in Target
  1141. Names: Special Targets.).  `.SILENT' is essentially obsolete since `@'
  1142. is more flexible.
  1143.  
  1144. 
  1145. File: make.info,  Node: Execution,  Next: Parallel,  Prev: Echoing,  Up: Commands
  1146.  
  1147. Command Execution
  1148. =================
  1149.  
  1150.    When it is time to execute commands to update a target, they are
  1151. executed by making a new subshell for each line.  (In practice, `make'
  1152. may take shortcuts that do not affect the results.)
  1153.  
  1154.    *Please note:* this implies that shell commands such as `cd' that
  1155. set variables local to each process will not affect the following
  1156. command lines.  If you want to use `cd' to affect the next command, put
  1157. the two on a single line with a semicolon between them.  Then `make'
  1158. will consider them a single command and pass them, together, to a shell
  1159. which will execute them in sequence.  For example:
  1160.  
  1161.      foo : bar/lose
  1162.              cd bar; gobble lose > ../foo
  1163.  
  1164.    If you would like to split a single shell command into multiple
  1165. lines of text, you must use a backslash at the end of all but the last
  1166. subline.  Such a sequence of lines is combined into a single line, by
  1167. deleting the backslash-newline sequences, before passing it to the
  1168. shell.  Thus, the following is equivalent to the preceding example:
  1169.  
  1170.      foo : bar/lose
  1171.              cd bar;  \
  1172.              gobble lose > ../foo
  1173.  
  1174.    The program used as the shell is taken from the variable `SHELL'.
  1175. By default, the program `/bin/sh' is used.
  1176.  
  1177.    Unlike most variables, the variable `SHELL' is never set from the
  1178. environment.  This is because the `SHELL' environment variable is used
  1179. to specify your personal choice of shell program for interactive use.
  1180. It would be very bad for personal choices like this to affect the
  1181. functioning of makefiles.  *Note Variables from the Environment:
  1182. Environment.
  1183.  
  1184. 
  1185. File: make.info,  Node: Parallel,  Next: Errors,  Prev: Execution,  Up: Commands
  1186.  
  1187. Parallel Execution
  1188. ==================
  1189.  
  1190.    GNU `make' knows how to execute several commands at once.  Normally,
  1191. `make' will execute only one command at a time, waiting for it to
  1192. finish before executing the next.  However, the `-j' or `--jobs' option
  1193. tells `make' to execute many commands simultaneously.
  1194.  
  1195.    If the `-j' option is followed by an integer, this is the number of
  1196. commands to execute at once; this is called the number of "job slots".
  1197. If there is nothing looking like an integer after the `-j' option,
  1198. there is no limit on the number of job slots.  The default number of job
  1199. slots is one, which means serial execution (one thing at a time).
  1200.  
  1201.    One unpleasant consequence of running several commands
  1202. simultaneously is that output from all of the commands comes when the
  1203. commands send it, so messages from different commands may be
  1204. interspersed.
  1205.  
  1206.    Another problem is that two processes cannot both take input from the
  1207. same device; so to make sure that only one command tries to take input
  1208. from the terminal at once, `make' will invalidate the standard input
  1209. streams of all but one running command.  This means that attempting to
  1210. read from standard input will usually be a fatal error (a `Broken pipe'
  1211. signal) for most child processes if there are several.
  1212.  
  1213.    It is unpredictable which command will have a valid standard input
  1214. stream (which will come from the terminal, or wherever you redirect the
  1215. standard input of `make').  The first command run will always get it
  1216. first, and the first command started after that one finishes will get
  1217. it next, and so on.
  1218.  
  1219.    We will change how this aspect of `make' works if we find a better
  1220. alternative.  In the mean time, you should not rely on any command using
  1221. standard input at all if you are using the parallel execution feature;
  1222. but if you are not using this feature, then standard input works
  1223. normally in all commands.
  1224.  
  1225.    If a command fails (is killed by a signal or exits with a nonzero
  1226. status), and errors are not ignored for that command (*note Errors in
  1227. Commands: Errors.), the remaining command lines to remake the same
  1228. target will not be run.  If a command fails and the `-k' or
  1229. `--keep-going' option was not given (*note Summary of Options: Options
  1230. Summary.), `make' aborts execution.  If make terminates for any reason
  1231. (including a signal) with child processes running, it waits for them to
  1232. finish before actually exiting.
  1233.  
  1234.    When the system is heavily loaded, you will probably want to run
  1235. fewer jobs than when it is lightly loaded.  You can use the `-l' option
  1236. to tell `make' to limit the number of jobs to run at once, based on the
  1237. load average.  The `-l' or `--max-load' option is followed by a
  1238. floating-point number.  For example,
  1239.  
  1240.      -l 2.5
  1241.  
  1242. will not let `make' start more than one job if the load average is
  1243. above 2.5.  The `-l' option with no following number removes the load
  1244. limit, if one was given with a previous `-l' option.
  1245.  
  1246.    More precisely, when `make' goes to start up a job, and it already
  1247. has at least one job running, it checks the current load average; if it
  1248. is not lower than the limit given with `-l', `make' waits until the load
  1249. average goes below that limit, or until all the other jobs finish.
  1250.  
  1251.    By default, there is no load limit.
  1252.  
  1253.